package com.atguigu.gmall.all.controller;

import com.atguigu.gmall.cart.client.CartFeignClient;
import com.atguigu.gmall.model.product.SkuInfo;
import com.atguigu.gmall.product.client.ProductFeignClient;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description:
 * @author: JC
 * @date: 2021/11/3 13:11
 */
@Controller
public class CartController {

    @Autowired
    private CartFeignClient cartFeignClient;

    @Autowired
    private ProductFeignClient productFeignClient;

    @GetMapping("addCart.html")
    public String addCart(Long skuId, Integer skuNum, ModelMap modelMap){

        cartFeignClient.addToCart(skuId,skuNum);

        // 存储skuInfo对象
        SkuInfo skuInfo = productFeignClient.getSkuInfo(skuId);
        modelMap.addAttribute("skuInfo",skuInfo);
        modelMap.addAttribute("skuNum",skuNum);

        return "cart/addCart";
    }


    @GetMapping("cart.html")
    public String cartList(){

        // 返回购物车列表也页面
        return "cart/index";
    }
}
